package com.woniuxy.listener;

import com.rabbitmq.client.Channel;
import com.woniuxy.entity.Mail;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: 马宇航
 * @Description: TODO
 * @DateTime: 22/10/20/0020 10:45
 * @Component: 成都蜗牛学苑
 **/
@Component
public class FanoutListener1 {
    @RabbitListener(queues = "myFanoutQueue1")
    public void listenerFanout(Mail mail, Channel channel, Message message) throws IOException, InterruptedException {
        //qos，是限流，每次可以从队列中取出的消息个数
        channel.basicQos(1);
        Thread.sleep(2000);
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        //每一个消息都会有一个tag标记的id，你要去队列中ack响应，必须要指定响应哪一条
        channel.basicAck(deliveryTag,false);
        System.out.println("广播第一个监听接受到消息："+mail);
    }
}
